package com.sf.ams.wordcount;

import java.util.Arrays;
import java.util.List;

import com.sf.ams.constant.Constant;
import com.sf.ams.utils.StringUtil;

/**
 * 描述：统计关键字DELIMITER的出现次数
 * 
 * <pre>HISTORY
 * ****************************************************************************
 *  ID   DATE           PERSON          REASON
 *  1    2017年12月7日      Simba.Hua         Create
 * ****************************************************************************
 * </pre>
 * @author Simba.Hua
 */
public class DelimiterWordCount {
	private static final String DELIMITER = Constant.DELIMITER;
	private DelimiterWordCount() {
		
	}
	public int count(String word) {
		if (StringUtil.isEmpty(word)) {
			return 0;
		}
		List<String> lineWords = Arrays.asList(word.split(Constant.SEQUENCE_SPLIT));
		int delimiterCount = 0;
		for (String lineWord : lineWords) {
			lineWord = lineWord.toUpperCase();
			if(Arrays.asList(lineWord.split(Constant.WORD_SPLIT)).contains(DELIMITER)) {
				delimiterCount ++;
			}
		}
		return delimiterCount;
	}
	private static class Singleton {
		private static DelimiterWordCount instance;
		
		static {
			instance  = new DelimiterWordCount();
		}
		private Singleton() {
			
		}
		private static DelimiterWordCount getInstance() {
			return instance;
		}
	}
	public static DelimiterWordCount getInstance() {
		return Singleton.getInstance();
	}
}
